package com.GZHU.controller;


import com.GZHU.fisco.BlockChainClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.HashMap;
import com.GZHU.fisco.Constant;
@Slf4j
@Controller
public class search_model_controller {

//    private Data_upload data_upload;
    @GetMapping("/search_model")
    // 查询模型存证溯源信息， HashMap<String,String>
    public String get_model_id(@RequestParam(value = "model_id") String model_id, Model model){
        HashMap<String,String> record=BlockChainClient.query_record(Constant.data_upload,model_id);
        ArrayList<String>state= BlockChainClient.query_state(Constant.data_upload,model_id);
        log.info(String.valueOf(state));
        // 去除多余的中括号
        model_id=record.get("模型号");
        model_id=model_id.substring(1,model_id.length()-1);
        String producer_id=record.get("生产者");
        producer_id=producer_id.substring(1,producer_id.length()-1);
        String verifyer_id=record.get("审核人");
        verifyer_id=verifyer_id.substring(1,verifyer_id.length()-1);
        String certifer_id=record.get("认证者");
        certifer_id=certifer_id.substring(1,certifer_id.length()-1);
        model.addAttribute("model_id",model_id);
        model.addAttribute("producer_id",producer_id);
        model.addAttribute("verifyer_id",verifyer_id);
        model.addAttribute("certifer_id",certifer_id);
        model.addAttribute("state",state);
//        System.out.println(record);
//        System.out.println(state);
        return "home";
//        return record;
    }

//    @GetMapping("/search_model?model_id={id}")
//    public String fun(@PathVariable("id") String id){
//        return "hahah";
////        return id;
//    }
}
